package com.lv.service.weidget.picker

import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.KeyboardUtils
import com.blankj.utilcode.util.LogUtils
import com.lv.common.imp.OnPositionTListener
import com.lv.common.ktx.filterLine
import com.lv.common.utils.showToast
import com.lv.service.R
import com.lxj.xpopup.impl.PartShadowPopupView

/**
 * 作者： ygx
 * 创建日期：2024/9/6 10:28 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：自定义带有输入框的Bottom弹窗
 */
class InputBottomPop(
    private val mContext: Context,
    private val mTitle: String,
    private val categoryName: String,
    private val categorySecoundName: String,
    private val positionListener: OnPositionTListener<String>? = null
) : PartShadowPopupView(mContext) {
    private var viewTop: View? = null
    private var mEditText: EditText? = null
    override fun getImplLayoutId(): Int {
        return R.layout.input_bottom_pop
    }

    override fun onCreate() {
        super.onCreate()
        initView()
        initEvnet()
    }

    private fun initView() {
        viewTop = findViewById<View>(R.id.view_top)
        mEditText = findViewById<EditText>(R.id.et_content)
        findViewById<TextView>(R.id.tv_title).text = mTitle
        findViewById<ImageView>(R.id.iv_close).setOnClickListener { dismiss() }
        findViewById<TextView>(R.id.tv_category).text = "$categoryName>$categorySecoundName"
        findViewById<TextView>(R.id.tv_submit).setOnClickListener {
            val etContent = mEditText?.text?.trim().toString().filterLine()
            if (etContent.isEmpty()) {
                showToast("请输入三级分类名称")
            } else {
                positionListener?.onClick(0, etContent)
                dismiss()
            }
        }
    }

    private var mKeyboardH = 0
    private fun initEvnet() {
        KeyboardUtils.registerSoftInputChangedListener(
            mContext as Activity
        ) { height ->
            handler.postDelayed(Runnable { mKeyboardH = height }, 500)

        }
        viewTop?.setOnClickListener {
            if (mKeyboardH == 0) {
                dismiss()
            }

        }

    }

    private fun setDismissDialog() {
        dismiss()
    }


    override fun onDestroy() {
        super.onDestroy()
    }

    override fun beforeDismiss() {
        super.beforeDismiss()


    }
}